import { ref, onMounted } from 'vue'
import { getCreatorList, getManageList } from '@/api/template'

export function useDict(type, callback) {
  const creatorList = ref([])
  const manageList = ref([])

  onMounted(() => {
    init()

    callback && callback()
  })
  const init = () => {
    getCreatorList(type).then((res) => {
      let list = []
      if (res.data && res.data.length > 0) {
        list = res.data.map((v) => {
          return {
            label: v.realName,
            value: v.id
          }
        })
      }
      creatorList.value = [...list]
    })
    getManageList(type).then((res) => {
      const obj = {
        label: '全选',
        value: ''
      }
      let list = []
      if (res.data && res.data.length > 0) {
        list = res.data.map((v) => {
          return {
            label: v.managePathName,
            value: v.manageId
          }
        })
      }
      manageList.value = [obj, ...list]
    })
  }
  return { creatorList, manageList, init }
}
